package com.example.maoyanmovie.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.example.maoyanmovie.databinding.ActivityOrderConfirmBinding;
import com.example.maoyanmovie.model.OrderInfo;
import com.example.maoyanmovie.utils.Constants;
import com.example.maoyanmovie.utils.ToastUtils;

public class OrderConfirmActivity extends AppCompatActivity {

    private ActivityOrderConfirmBinding binding;
    private OrderInfo orderInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityOrderConfirmBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        // 接收订单信息
        orderInfo = (OrderInfo) getIntent().getSerializableExtra(Constants.INTENT_KEY_ORDER_INFO);

        initView();
        loadOrderInfo();
    }

    private void initView() {
        binding.ivBack.setOnClickListener(v -> finish());

        binding.btnPay.setOnClickListener(v -> {
            if (orderInfo != null) {
                ToastUtils.showShort(this, "支付成功！总价：¥" + String.format("%.0f", orderInfo.getTotalPrice()));
            } else {
                ToastUtils.showShort(this, "支付成功");
            }
            // 返回到主页
            finish();
        });
    }

    private void loadOrderInfo() {
        if (orderInfo == null) {
            binding.tvMovieName.setText("订单信息加载失败");
            return;
        }

        // 显示真实订单数据
        binding.tvMovieName.setText("电影：" + orderInfo.getMovieName());
        binding.tvCinemaName.setText("影院：" + orderInfo.getCinemaName());
        binding.tvShowTime.setText("时间：" + orderInfo.getShowTime());
        binding.tvSeats.setText("座位：" + orderInfo.getSeatsString());
        binding.tvTotalPrice.setText("合计：¥" + String.format("%.0f", orderInfo.getTotalPrice()));
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        binding = null;
    }
}
